/*
    计算器
*/
#pragma once
#include "protocol.hpp"

class Calculate
{
public:
    protocol_ns::Response excute(protocol_ns::Request &req)
    {
        protocol_ns::Response res;
        switch (req._oper)
        {
        case '+':
            res._result = req._x + req._y;
            break;
        case '-':
            res._result = req._x - req._y;
            break;
        case '*':
            res._result = req._x * req._y;
            break;
        case '/':
        {
            if (req._y == 0)
            {
                res._state = 1;
            }
            else
            {
                res._result = req._x / req._y;
            }
        }
        break;
        case '%':
        {
            if (req._y == 0)
            {
                res._state = 2;
            }
            else
            {
                res._result = req._x % req._y;
            }
        }
        break;
        default:
            res._state = 3;
            break;
        }
        return res;
    }
};